package com.wtx.controller;

import com.wtx.entities.CommonResult;
import com.wtx.entities.Payment;
import com.wtx.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/payment")
    public CommonResult create(@RequestBody Payment payment){
        int i = paymentService.create(payment);
        log.info("***************插入结果："+i+"********************");
        if (i > 0) {
            return new CommonResult(200,"成功:"+serverPort,i);
        }else {
            return new CommonResult(444,"失败",null);
        }
    }
    @GetMapping("/payment/{id}")
    public CommonResult get(@PathVariable("id") Integer id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("****************************查询结果："+payment);
        if (payment == null) {
            return new CommonResult(444,"失败",null);
        }else {
            return new CommonResult(200,"成功",payment);
        }
    }
}
